package com.ssyan.factory.simplefactory.order;

import com.ssyan.factory.simplefactory.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author ssyan
 * @Description 使用静态简单工厂
 * @create 2021/8/27 23:20
 * @Version 1.0
 */
public class OrderPizza2 {

    Pizza pizza = null;
    String orderType;

    //构造器
    public OrderPizza2() {
        do {
            orderType = getType();
            pizza = SimpleFactory.createPizza(orderType);

            //输出pizza
            if (pizza != null) {
                pizza.setName(orderType);
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购披萨失败");
                break;
            }
        }while (true);
    }


    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
